﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Diagnostics;
using Xeml.Visualization;
using Mpi.Common.Graphic;

namespace Xeml.Visualization.Controls
{
    public partial class MultiTimeLineScale : ScrollableControl
    {

        #region Fields
        const string week = "week";
        const string day = "day";
        const string hour = "hour";
        const string minute = "minute";

        private Brush inactiveBrush;
        private Brush activeBrush;
        private Brush inactivePenBrush;
        private Color mainColor;
        private Pen activeBorderPen;
        private Pen activeTimePen;
        private Pen inactiveTimePen;
        private Pen activeSliderPen;
        private Pen inactiveSliderPen;
        private Pen previewSliderPen;
        private Pen zoomPen;
        private Pen timeHelpLinePen;
        private Image zoom;
        private Brush zoomInBrush;
        private Brush zoomOutBrush;
        private Font currentTimeFont;
        private Font timeLabelFont;

        private Rectangle weekLabelBox;
        private Rectangle dayLabelBox;
        private Rectangle hourLabelBox;
        private Rectangle minuteLabelBox;

        private int x;
        private int y;
        private bool mouseIsOver;
        private bool mouseIsDown;
        #endregion

        #region Properties

        private DrawAreaStyle _drawAreaStyle = DrawAreaStyle.GreenMetal;

        public DrawAreaStyle DrawAreaStyle
        {
            get { return _drawAreaStyle; }
            set { _drawAreaStyle = value; Invalidate(); }
        }

        /// <summary>
        /// Indicate whether or not the mouse is ocer this control.
        /// </summary>
        public bool MouseIsOver
        {
            get { return mouseIsOver; }
            set
            {
                mouseIsOver = value;
                this.Invalidate();
            }
        }

        /// <summary>
        /// Indicates whether or not the left mose button is pressed.
        /// </summary>
        public bool MouseIsDown
        {
            get { return mouseIsDown; }
            set
            {
                mouseIsDown = value;
                this.Invalidate();
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public new Size Size
        {
            get
            {
                return base.Size;
            }
            set
            {
                //value.Height = 90;
                //base.Size = value;
            }
        }


        //private new int Height
        //{
        //    get
        //    {
        //        return base.Height;
        //    }
        //    set
        //    {
        //        base.Height = 90;
        //    }
        //}

        //public new int Width
        //{
        //    get
        //    {
        //        return base.Width;
        //    }
        //    set
        //    {
        //        base.Width = value;
        //    }
        //}


        #endregion


        #region Constructors

        /// <summary>
        /// The standard constructor
        /// </summary>
        public MultiTimeLineScale()
        {

            //this.DoubleBuffered = true;
            //SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            //SetStyle(ControlStyles.ResizeRedraw, true);
            
            InitializeComponent();
            this.AutoScroll = true;

            this.SetStyle(ControlStyles.DoubleBuffer | 
            ControlStyles.UserPaint |
            ControlStyles.AllPaintingInWmPaint,
            true);
            this.UpdateStyles();
            
            //this.BackColor = Color.Transparent;
            this.DoubleBuffered = true;
            
            //Init a default pixel mapper
            //this.pxMapper = new TimeRegionPixelMapper();
            
            //TimeRegion tr = new TimeRegion();
            //tr.Length = TimeSpan.FromDays(35);
            //this.pxMapper.Regions.AddFirst(tr);
            //this.pxMapper.InterStepSpace = 1;


            //this.pxMapper.SplitRegion(TimeSpan.FromDays(8));


            this.mainLine = new GraphicsPath();
            this.slider = new List<Slider>();
            currentTimeDisplay = new Rectangle(this.rowHeaderWidth, 1, 100, 18);
            currentTime = TimeSpan.Zero.ToString();

            Setup(pxMapper);
            zoom = (Image)BackgroundRes.Zoom;
            SetupTimeDisplay();

            //A test time editor
            //this.timeEditor = new TimeEditor(TimeSpan.FromDays(7), pxMapper);
            //this.timeEditor.Y = 30;
            //this.timeEditor.XOffset = rowHeaderWidth;
            //this.timeEditor.TimeChanged += new EventHandler(timeEditor_TimeChanged);
            //ActivateTimeEditor(TimeSpan.FromDays(14), TimeSpan.FromDays(0), TimeSpan.FromDays(35));

            //InitDrawTools();
           
        }

    


        #endregion

        #region Methods

        private Rectangle TranslateTransform(Rectangle r)
        {
            return new Rectangle(r.X + AutoScrollPosition.X, r.Y + AutoScrollPosition.Y, r.Width, r.Height);
        }

        private void InitDrawTools()
        {
            mainColor = Color.FromArgb(255, 255, 255);
            inactiveBrush = new LinearGradientBrush(this.mainArea, Color.FromArgb(0, mainColor), Color.FromArgb(200, mainColor), 270f);
            inactivePenBrush = new LinearGradientBrush(this.mainArea, Color.FromArgb(0, Color.Gray), Color.FromArgb(200, Color.Gray), 270f);

            activeBrush = new LinearGradientBrush(this.mainArea, Color.FromArgb(20, mainColor), Color.FromArgb(210, mainColor), 270f);
            activeBorderPen = new Pen(Color.Silver);
            activeTimePen = new Pen(Color.Black);
            inactiveTimePen = new Pen(Color.FromArgb(40,40,40)); 
            activeSliderPen = new Pen(Color.Black, 2);
            inactiveSliderPen = new Pen(inactivePenBrush);
            previewSliderPen = new Pen(Color.Black, 1);
            previewSliderPen.DashStyle = DashStyle.Dash;

            zoomPen = new Pen(Color.SteelBlue, 2f);
            zoomInBrush = new SolidBrush(Color.FromArgb(65, Color.SteelBlue));
            zoomOutBrush = new SolidBrush(Color.FromArgb(65, Color.Red));

            currentTimeFont = new Font("Verdana", 10f);
            timeLabelFont = new Font("Verdana", 7f);

            Size boxSize;
            
            boxSize = TextRenderer.MeasureText(minute, timeLabelFont);
            minuteLabelBox = new Rectangle(rowHeaderWidth - boxSize.Width - 2, mainLineY + 5, boxSize.Width, boxSize.Height);
            boxSize = TextRenderer.MeasureText(hour, timeLabelFont);
            hourLabelBox = new Rectangle(rowHeaderWidth - boxSize.Width - 2, minuteLabelBox.Bottom + 0, boxSize.Width, boxSize.Height);
            boxSize = TextRenderer.MeasureText(day, timeLabelFont);
            dayLabelBox = new Rectangle(rowHeaderWidth - boxSize.Width - 2, hourLabelBox.Bottom + 0, boxSize.Width, boxSize.Height);
            boxSize = TextRenderer.MeasureText(week, timeLabelFont);
            weekLabelBox = new Rectangle(rowHeaderWidth - boxSize.Width - 2, dayLabelBox.Bottom + 0, boxSize.Width, boxSize.Height);

            timeHelpLinePen = new Pen(Color.LightGray, 1);
            timeHelpLinePen.DashStyle = DashStyle.Dash;
        }
        #endregion
        
        #region Painting stuff

        private void PaintMe(Graphics g, Rectangle clipRectangle)
        {


            int width = (int)Math.Max(this.Width, this.AutoScrollMinSize.Width);
            int height = (int)Math.Max(this.Height, this.AutoScrollMinSize.Height);

            //PaintBackground(g, width, height);

            //if (mouseIsOver)
            //{
                PaintActiveState(g);
            //}
            //else
            //{
            //    PaintInactiveState(g);
            //}

            //g.DrawRectangle(Pens.SteelBlue, currentTimeDisplay);
            //if (activeTimeEditor)
            //    TextRenderer.DrawText(g, this.currentTime, currentTimeFont, TranslateTransform(this.currentTimeDisplay), Color.SteelBlue);

            if (activeSlider >= 0)
            {
                PaintActiveSlider(g);
            }


            //g.TranslateTransform(this.rowHeaderWidth, 0);
            if (pxMapper != null)
            {
                PaintTimeSteps(g, clipRectangle);
            }

            //g.TranslateTransform(-this.rowHeaderWidth, 0);
            if (this.timeEditor != null)
            {
                PaintActiveTimeEditor(g);
            }

            
        }

        //private void PaintBackground(Graphics g, int width, int height)
        //{
        //    Image bck = null;
        //    switch (DrawAreaStyle)
        //    {
        //        case DrawAreaStyle.GreenMetal:
        //            {
        //                bck = BackgroundRes.GreenMetalBand;
        //                break;
        //            }
        //        case DrawAreaStyle.BlueMetal:
        //            {
        //                bck = BackgroundRes.BlueMetalBand;
        //                break;
        //            }
        //        case DrawAreaStyle.SilverMetal:
        //            {
        //                bck = BackgroundRes.SilverMetalBand;
        //                break;
        //            }
        //        default:
        //            {
        //                bck = BackgroundRes.GreenMetalBand;
        //                break;
        //            }
        //    }
        //    int horiCount = (width / bck.Width) + 1;
        //    int vertCount = (height / bck.Height) + 1;
        //    for (int i = 0; i < horiCount; i++)
        //    {
        //        for (int j = 0; j < vertCount; j++)
        //        {
        //            g.DrawImage(bck, i * bck.Width, j * bck.Height);
        //        }
        //    }
        //}

        private void PaintActiveTimeEditor(Graphics g)
        {
            //if (activeTimeEditor || highLightTimeEditor)
            //{
               // g.FillPath(zoomInBrush, this.timeEditor.Shape);
                g.DrawPath(Pens.Firebrick, this.timeEditor.Shape);
            //}
            //else
            //    g.DrawPath(new Pen(zoomInBrush), this.timeEditor.Shape);
        }


        private  List<int> allreadyPaintedSteps = new List<int>();
        private void PaintTimeSteps(Graphics g, Rectangle clipRectangle)
        {
            allreadyPaintedSteps.Clear();
            //Rectangle prevLabelBox = default(Rectangle);
            //Rectangle currLabelBox = default(Rectangle);
            Pen p;
            if (mouseIsOver)
                p = activeTimePen;
            else
                p = inactiveTimePen;
            //foreach (int x in pxMapper.WeekSteps)
            //{
            //    g.DrawLine(p, x, mainLineY, x, weekLabelBox.Top);
            //    Size sz = TextRenderer.MeasureText((((int)(pxMapper.MapPoint(x).TotalDays) / 7)).ToString(), timeLabelFont);
            //    int xpos = rowHeaderWidth + x - (sz.Width / 2);
            //    currLabelBox = new Rectangle(xpos, weekLabelBox.Top, sz.Width, sz.Height);
            //    if (prevLabelBox.Right <= currLabelBox.Left && x > 0)
            //    {
            //        TextRenderer.DrawText(g, (((int)(pxMapper.MapPoint(x).TotalDays) / 7)).ToString(), timeLabelFont, TranslateTransform(currLabelBox), Color.Black);
            //        prevLabelBox = currLabelBox;
            //    }
            //}
            //prevLabelBox = default(Rectangle);
            //currLabelBox = default(Rectangle);
            //foreach (int x in pxMapper.DaySteps)
            //{
            //    g.DrawLine(p, x, mainLineY, x, dayLabelBox.Top);
            //    Size sz = TextRenderer.MeasureText((pxMapper.MapPoint(x).Days % 7).ToString(), timeLabelFont);
            //    int xpos = rowHeaderWidth + x - (sz.Width / 2);
            //    currLabelBox = new Rectangle(xpos, dayLabelBox.Top, sz.Width, sz.Height);
            //    if (prevLabelBox.Right <= currLabelBox.Left)
            //    {
            //        TextRenderer.DrawText(g, (pxMapper.MapPoint(x).Days % 7).ToString(), timeLabelFont, TranslateTransform(currLabelBox), Color.Black);
            //        prevLabelBox = currLabelBox;
            //    }
            //}


            int maxRes = 60;
            foreach (TimeRegion tr in pxMapper.Regions)
            {
                maxRes = Math.Min(maxRes, tr.MinutesPerPixel);
            }

            for (int i = 0; i < this.pxMapper.Regions.Length.TotalDays; i += 7)
            {
                int x = pxMapper.MapPoint(TimeSpan.FromDays(i));
                x = pxMapper.LogicPixelAddressOf(x);
                x += rowHeaderWidth;
                //if (x > previouseStep + 9 || x == rowHeaderWidth)
                //{
                if (x >= clipRectangle.Left && x <= clipRectangle.Right && !allreadyPaintedSteps.Contains(x))
                {
                    allreadyPaintedSteps.Add(x);
                    g.DrawLine(p, x, this.mainArea.Top, x, this.mainArea.Bottom);
                }
                //    previouseStep = x;
                //}
            }


            for (int i = 0; i < this.pxMapper.Regions.Length.TotalDays; i++)
            {
                int x = pxMapper.MapPoint(TimeSpan.FromDays(i));
                x = pxMapper.LogicPixelAddressOf(x);
                x += rowHeaderWidth;
                //if (x > previouseStep + 9 || x == rowHeaderWidth)
                //{
                if (x >= clipRectangle.Left && x <= clipRectangle.Right && !allreadyPaintedSteps.Contains(x))
                {
                    allreadyPaintedSteps.Add(x);
                    g.DrawLine(p,  x, this.mainArea.Top+2, x, this.mainArea.Bottom-2);
                }
                //    previouseStep = x;
                //}
            }

   
            for (int i = 0; i < this.pxMapper.Regions.Length.TotalHours; i++)
            {
                int x = pxMapper.MapPoint(TimeSpan.FromHours(i));
                x = pxMapper.LogicPixelAddressOf(x);
                x += rowHeaderWidth;
                if (x >= clipRectangle.Left && x <= clipRectangle.Right && !allreadyPaintedSteps.Contains(x))
                {
                    //if (x > previouseStep + 4 || x == rowHeaderWidth)
                    //{

                    allreadyPaintedSteps.Add(x);
                    g.DrawLine(p, x, this.mainArea.Top + 4, x, this.mainArea.Bottom - 4);
                    //previouseStep = x;
                    //}
                }
            }

            if (maxRes < 60)
            {
                for (int i = 0; i < this.pxMapper.Regions.Length.TotalMinutes; i++)
                {
                    int x = pxMapper.MapPoint(TimeSpan.FromMinutes(i));
                    x = pxMapper.LogicPixelAddressOf(x);
                    x += rowHeaderWidth;

                    if (x >= clipRectangle.Left && x <= clipRectangle.Right && !allreadyPaintedSteps.Contains(x))
                    {
                        //if (x > previouseStep + 4 || x == rowHeaderWidth)
                        //{

                        allreadyPaintedSteps.Add(x);
                        g.DrawLine(p, x, this.mainArea.Top + 6, x, this.mainArea.Bottom - 6);
                        //previouseStep = x;
                        //}
                    }

                    //if (x > previouseStep + 4 || x == rowHeaderWidth)
                    //{
                    //g.DrawLine(p, rowHeaderWidth + x, this.mainArea.Top + 4, rowHeaderWidth + x, this.mainArea.Bottom - 4);
                    //  previouseStep = x;
                    //}
                }
            }

           // previouseStep = rowHeaderWidth;
          
            //prevLabelBox = default(Rectangle);
            //currLabelBox = default(Rectangle);
            //foreach (int x in pxMapper.HourSteps)
            //{
            //    g.DrawLine(p, x, mainLineY, x, hourLabelBox.Top);
            //    Size sz = TextRenderer.MeasureText((pxMapper.MapPoint(x).Hours % 24).ToString(), timeLabelFont);
            //    int xpos = rowHeaderWidth + x - (sz.Width / 2);
            //    currLabelBox = new Rectangle(xpos, hourLabelBox.Top, sz.Width, sz.Height);
            //    if (prevLabelBox.Right <= currLabelBox.Left)
            //    {
            //        TextRenderer.DrawText(g, (pxMapper.MapPoint(x).Hours % 24).ToString(), timeLabelFont, TranslateTransform(currLabelBox), Color.Black);
            //        prevLabelBox = currLabelBox;
            //    }
            //}
            //prevLabelBox = default(Rectangle);
            //currLabelBox = default(Rectangle);
            //foreach (int x in pxMapper.MinuteSteps)
            //{
            //    g.DrawLine(p, x, mainLineY, x, minuteLabelBox.Top);
            //    //Size sz = TextRenderer.MeasureText(pxMapper.MapPoint(x).Minutes.ToString(), timeLabelFont);
            //    //int xpos = rowHeaderWidth + x - (sz.Width / 2);
            //    //currLabelBox = new Rectangle(xpos, minuteLabelBox.Top, sz.Width, sz.Height);
            //    //if (prevLabelBox.Right <= currLabelBox.Left)
            //    //{
            //    //    TextRenderer.DrawText(g, pxMapper.MapPoint(x).Minutes.ToString(), timeLabelFont, currLabelBox, Color.Black);
            //    //    prevLabelBox = currLabelBox;
            //    //}
            //}
        }

        private void PaintActiveSlider(Graphics g)
        {
            g.DrawPath(previewSliderPen, slider[activeSlider].PreviewLine);
            int xPos = (int)slider[activeSlider].X;
            if (slider[activeSlider].MoveDirection == -1)
            {
                g.FillRectangles(zoomOutBrush, new RectangleF[] { slider[activeSlider].PreviewZoomArea });
                g.DrawImage(zoom, xPos + 3, 5);
                //g.DrawLine(zoomPen, xPos - 17, 12, xPos - 10, 12);
                g.DrawLine(zoomPen, xPos + 6, 12, xPos + 14, 12);

            }
            else
            {
                g.FillRectangles(zoomInBrush, new RectangleF[] { slider[activeSlider].PreviewZoomArea });
                g.DrawImage(zoom, xPos + 3, 5);
                g.DrawLine(zoomPen, xPos + 6, 12, xPos + 14, 12);
                g.DrawLine(zoomPen, xPos + 10, 8, xPos + 10, 16);
            }
        }

        private void PaintInactiveState(Graphics g)
        {
            //g.FillRectangle(inactiveBrush, this.mainArea);
            //g.FillRectangle(inactiveBrush, this.rowHeaderArea);
            
            
            g.DrawPath(inactiveTimePen, this.mainLine);


            TextRenderer.DrawText(g, minute, timeLabelFont, TranslateTransform(minuteLabelBox), Color.LightGray);
            TextRenderer.DrawText(g, hour, timeLabelFont, TranslateTransform(hourLabelBox), Color.LightGray);
            TextRenderer.DrawText(g, day, timeLabelFont, TranslateTransform(dayLabelBox), Color.LightGray);
            TextRenderer.DrawText(g, week, timeLabelFont, TranslateTransform(weekLabelBox), Color.LightGray);
            foreach (Slider sl in this.slider)
            {
                g.DrawPath(inactiveSliderPen, sl.Line);
            }

            GraphicEffect.DrawGlassRectangle(g, this.mainArea, Color.Black,20, 0.10f, true);
            GraphicEffect.DrawGlassRectangle(g, this.rowHeaderArea, Color.Black,20, 0.10f, true);
        }

        private void PaintActiveState(Graphics g)
        {
            //g.FillRectangle(activeBrush, this.mainArea);
            //g.FillRectangle(activeBrush, this.rowHeaderArea);


            //g.DrawRectangle(activeBorderPen, this.rowHeaderArea);
            g.DrawRectangle(activeBorderPen, this.mainArea);
            g.FillRectangle(Brushes.WhiteSmoke, this.mainArea);
            g.DrawLine(Pens.Silver, 0, Math.Max(this.Height - 1, 1), this.Width, Math.Max(this.Height - 1, 1));

            //if (pxMapper != null && pxMapper.MinuteSteps.Length > 0)
            //    TextRenderer.DrawText(g, minute, timeLabelFont, TranslateTransform(minuteLabelBox), Color.Black);
            //else
            //    TextRenderer.DrawText(g, minute, timeLabelFont, TranslateTransform(minuteLabelBox), Color.LightGray);
            //if (pxMapper != null && pxMapper.HourSteps.Length > 0)
            //    TextRenderer.DrawText(g, hour, timeLabelFont, TranslateTransform(hourLabelBox), Color.Black);
            //else
            //    TextRenderer.DrawText(g, hour, timeLabelFont, TranslateTransform(hourLabelBox), Color.LightGray);
            //if (pxMapper != null && pxMapper.DaySteps.Length > 0)
            //    TextRenderer.DrawText(g, day, timeLabelFont, TranslateTransform(dayLabelBox), Color.Black);
            //else
            //    TextRenderer.DrawText(g, day, timeLabelFont, TranslateTransform(dayLabelBox), Color.LightGray);
            //if (pxMapper != null && pxMapper.WeekSteps.Length > 1)
            //    TextRenderer.DrawText(g, week, timeLabelFont, TranslateTransform(weekLabelBox), Color.Black);
            //else
            //    TextRenderer.DrawText(g, week, timeLabelFont, TranslateTransform(weekLabelBox), Color.LightGray);

            //g.DrawLine(timeHelpLinePen, this.rowHeaderWidth - 5, minuteLabelBox.Bottom - 2, this.mainArea.Right, minuteLabelBox.Bottom - 2);
            //g.DrawLine(timeHelpLinePen, this.rowHeaderWidth - 5, hourLabelBox.Bottom - 2, this.mainArea.Right, hourLabelBox.Bottom - 2);
            //g.DrawLine(timeHelpLinePen, this.rowHeaderWidth - 5, dayLabelBox.Bottom - 2, this.mainArea.Right, dayLabelBox.Bottom - 2);
            //g.DrawLine(timeHelpLinePen, this.rowHeaderWidth - 5, weekLabelBox.Bottom - 2, this.mainArea.Right, weekLabelBox.Bottom - 2);
            foreach (Slider sl in this.slider)
            {
                g.DrawPath(activeSliderPen, sl.Line);
            }


            if (activeSlider >= 0)
                TextRenderer.DrawText(g, this.currentZoomFactor, currentTimeFont, TranslateTransform(this.currentZoomDisplay), Color.SteelBlue);


            //GraphicEffect.DrawGlassRectangle(g, this.mainArea, Color.Black,35, 0.10f, true);
            //GraphicEffect.DrawGlassRectangle(g, this.rowHeaderArea, Color.Black,35, 0.10f, true);
        }

        #endregion

        #region Event handling
        /// <summary>
        /// The paint eventhandler method.
        /// </summary>
        /// <param name="pe">Paint event argument.</param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics g = pe.Graphics;

            g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
            //g.DrawRectangle(Pens.Black, new Rectangle(10, 10, 30, 30));

            PaintMe(g, pe.ClipRectangle);

            //OnPaint-Basisklasse wird aufgerufen
            base.OnPaint(pe);
        }

        /// <summary>
        /// Mouse down event handler method.
        /// </summary>
        /// <param name="e">Mouse event argument.</param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            // Debug.WriteLine("MouseDown");
            if (e.Button == MouseButtons.Left)
            {
                this.MouseIsDown = true;
                x = e.X;
                y = e.Y;
                this.activeTimeEditor = HitTestTimeEditor(e.X, e.Y);
                if(!activeTimeEditor)
                    this.activeSlider = HitTestSlider(e.X, e.Y, 3);
                
            }
        }

        /// <summary>
        /// Mouse up event handler method.
        /// </summary>
        /// <param name="e">Mouse event argument.</param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.Button == MouseButtons.Left)
            {
                this.MouseIsDown = false;
                if (this.activeSlider >= 0)
                {
                    this.slider[activeSlider].ApplyChange();
                    this.activeSlider = -1;

                    Invalidate(false);
                }
                if (this.activeTimeEditor)
                {
                    AcceptTimeEdit();
                    this.activeTimeEditor = false;
                }
            }
        }

        /// <summary>
        /// Mouse enter event handler method.
        /// </summary>
        /// <param name="e">Mouse event argument.</param>
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            this.MouseIsOver = true;
            //Debug.WriteLine("MouseEnter");
        }

        /// <summary>
        /// Mouse leave event handler method.
        /// </summary>
        /// <param name="e">Mouse event argument.</param>
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            this.MouseIsOver = false;
            //Debug.WriteLine("MouseLeave");
        }

        /// <summary>
        /// Mouse over event handler method.
        /// </summary>
        /// <param name="e">Mouse event argument.</param>
        //protected override void OnMouseHover(EventArgs e)
        //{
        //    base.OnMouseHover(e);
        //    //Debug.WriteLine("MouseHover");
        //}


        /// <summary>
        /// Mouse move event handler method.
        /// </summary>
        /// <param name="e">Mouse event argument.</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            int hit = HitTestSlider(e.X, e.Y, 3);
            this.HighLightTimeEditor = HitTestTimeEditor(e.X, e.Y);

            


            if (activeSlider >= 0)
            {
                if (e.X > this.Width - 22 && slider[activeSlider].MoveDirection == 1)
                    this.Width = e.X + 22;
                slider[activeSlider].X = e.X;


                this.currentZoomFactor = this.slider[activeSlider].PreviewZoomFactor().ToString() + "%";
                this.currentZoomDisplay.Width = TextRenderer.MeasureText(this.currentZoomFactor, this.currentTimeFont).Width;
                this.currentZoomDisplay.X = Math.Max(e.X - this.currentZoomDisplay.Width - 5, (int)this.slider[activeSlider].LeftWall - this.currentZoomDisplay.Width );
                this.currentZoomDisplay.Y = 3;
                this.currentZoomDisplay.Height = this.Height -6;

                Invalidate(false);
                return;
            }



            if (hit > -1)
            {
                Cursor = Cursors.VSplit;

            }
            else
            {
                Cursor = Cursors.Cross;

            }

            if (activeTimeEditor)
            {
                this.MoveTimeEditor(e.X - this.timeEditor.XOffset);
                //this.timeEditor.X = e.X - this.timeEditor.XOffset;
            }

        
            //Invalidate(false);
        }



        #endregion

    }
}
